/**
 * 代码补全服务
 * 提供代码补全和建议功能
 */
import { CompletionItem, CompletionItemKind } from 'vscode-languageserver/node'
import { TextDocumentPositionParams } from 'vscode-languageserver/node'
import { keywordData } from '../data'

/**
 * 生成代码补全项
 * 将关键字数据转换为补全项
 * @param params 文本文档位置参数
 * @returns 补全项数组
 */
export const provideCompletionItems = (
	_params: TextDocumentPositionParams
): CompletionItem[] => {
	// 将关键字数据转换为补全项
	return keywordData.map(item => {
		return {
			label: item.label,
			kind: CompletionItemKind.Keyword,
			data: item.data
		}
	})
}

/**
 * 解析补全项的详细信息
 * 为补全项提供详细说明和文档
 * @param item 补全项
 * @returns 补充了详细信息的补全项
 */
export const resolveCompletionItem = (
	item: CompletionItem
): CompletionItem => {
	// 查找对应的补全数据
	const result = keywordData.find(i => i.data === item.data)
	if (result) {
		item.detail = result.detail
		item.documentation = result.documentation
	}
	return item
}